package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.domain.dto.req.SupplierCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.SupplierQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.SupplierUpdateDTO;
import com.winshare.saleAssistant.service.SupplierService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/sys/supplier")
@CrossOrigin
@Api(value = "供应商管理",description = "供应商管理")
public class SupplierController {

    private final SupplierService supplierService;

    public SupplierController(SupplierService supplierService) {
        this.supplierService = supplierService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增供应商接口")
    public LogicResponse save(@RequestBody @Validated SupplierCreateDTO supplierCreateDTO) {
        supplierService.saveSupplier(supplierCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改供应商接口")
    public LogicResponse update(@RequestBody @Validated SupplierUpdateDTO supplierUpdateDTO) {
        supplierService.updateSupplier(supplierUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查询单个供应商的详情")
    public LogicResponse getSupplierDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(supplierService.getSupplierDetail(baseIdDTO));
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除某个供应商")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        supplierService.deleteSupplier(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取供应商列表")
    public LogicResponse getSupplierList(@RequestBody @Validated SupplierQueryDTO supplierQueryDTO) {
        return LogicResponse.success(supplierService.getSupplierList(supplierQueryDTO));
    }

    // todo 生产秘钥接口
}
